\section{Firmware logic.}

Filght control firmware consists of two routines:

\begin{enumerate}
\item Main program.
\item Interrupt service routine (ISR).
\end{enumerate}

\subsection{Main Program.}

The main program takes control from the moment the altimeter is turned on.
It takes care of:

\begin{enumerate}
\item Configuring all the pins of the microcontroller.
\item Configuration of the events that the Interrupt Service Routine will activate.
\item Communication, through the acustic/optic interface, of the different states
   of the system, and the maximum altitud reached, according to preestablished
   protocol.
\item Detection of all relevant events during the flight of the rocket:

   \begin{itemize}
   \item Rocket on ramp.
   \item Takeoff.
   \item Apogee.
   \item Main recovery system ejection altitude.
   \item Landing.
   \end{itemize}

\item Control of the recovery system, according to the events detected.

\end{enumerate}

A flow diagram of this module can be found in the appendix.

\subsection{Interrupt Service Routine (ISR)}

This routine is activated every time the TIMER0 of the microcontroller is
overflowed. This overflow is programmed to happen every 4.096 ms.

Every time the routine is executed, it performs a series of operations:

\begin{enumerate}
\item Controls the aquisition of analogic data from the pressure sensor.
\item Processes the obtained digital data.
\end{enumerate}

The digital processing of the signal consists in a filtering of data
to avoid detection of false events (takeoff, apogee, main recovery
system deployment and landing), and to make sure the maximum altitude
estimation has adequate precision and accuracy.

The flow diagram of this module can be found in the appendix.
The firmware was written in assembly language and compiled using the MicroChip MPLAB package.

For the recording of the firmware on the microcontroller, the IC-PROG software
was used, along with a low cost JDM programming board.
